/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package view;

import control.MStockMidlet;
import listener.ICancelListener;
import listener.Command;
import listener.ICommandListener;
import ui.CustomGauge;

/**
 *
 * @author Kien.Tran
 */
public class ProcessBox implements ICommandListener {

    private MStockMidlet control;
    private CustomGauge gauge;
    private Command back;
    private ICancelListener listener;
    private int accent;
    private String[] lang;

    public ProcessBox(MStockMidlet control, int accent) {
        this.control = control;
        this.accent = accent;
    }

    private void initData() {
        if (accent <= 2) {
            lang = new String[]{"Đang kết nối", "Đang tải", "Vui lòng chờ", "Hủy"};
        }
    }

    private void initGui() {
        back = new Command(lang[3], Command.BACK);
        gauge = new CustomGauge(control.getBackground(), new String[]{lang[2], lang[0], lang[1]}, control);
        gauge.setBackCommand(back);
        gauge.setListener(this);
        gauge.setProgress(1);
    }

    public void setValue(int value) {
        gauge.setProgress(value);
    }

    public void setListener(ICancelListener listener) {
        this.listener = listener;
    }

    public void commandAction(Command command) {
        if (listener != null) {
            listener.cancelAction();
        }
        if (!(control.isCompleted()))
            control.back(0);
    }

    public void show() {
        initData();
        initGui();
        gauge.show();
    }
}
